package com.evaluationSystem.service.impl;

import com.evaluationSystem.entity.Weight;
import com.evaluationSystem.exception.EvaluationException;
import com.evaluationSystem.mapper.WeightMapper;
import com.evaluationSystem.service.WeightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName WeightServiceImpl
 * @Description TODO
 * @Author yinzhenxing
 * @Date 2023/1/4 17:59
 **/
@Service
public class WeightServiceImpl implements WeightService {
    @Autowired
    private WeightMapper weightMapper;

    @Override
    public List<Weight> getInfo(String questionId) {
        return weightMapper.getInfo(questionId);
    }

    @Override
    public void saveWeight(Weight weight) {
        if (100 != weight.getLevel1() + weight.getLevel2() + weight.getLevel3() + weight.getLevel4() + weight.getLevel5() + weight.getLevel6() + weight.getLevel7() + weight.getLevel8()) {
            throw new EvaluationException("权重之和必须为100");
        }

        weightMapper.saveWeight(weight);
    }

    @Override
    public void editWeight(Weight weight) {
        if (100 != weight.getLevel1() + weight.getLevel2() + weight.getLevel3() + weight.getLevel4() + weight.getLevel5() + weight.getLevel6() + weight.getLevel7() + weight.getLevel8()) {
            throw new EvaluationException("权重之和必须为100");
        }

        weightMapper.editWeight(weight);
    }

    @Override
    public void delWeight(Map<String, Object> map) {
        weightMapper.delWeight(map);
    }

}
